package com.yby6.web.controller.system;

import java.util.List;

import com.yby6.common.utils.poi.ExcelUtil;
import com.yby6.system.domain.SysAttachment;
import com.yby6.system.service.ISysAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yby6.common.core.controller.BaseController;
import com.yby6.common.core.AjaxResult;
import com.yby6.common.core.page.TableDataInfo;

/**
 * 附件Controller
 *
 * @author yangbuyi
 * @date 2022-04-17
 */
@RestController
@RequestMapping("/system/attachment")
public class SysAttachmentController extends BaseController {
    @Autowired
    private ISysAttachmentService sysAttachmentService;

    /**
     * 查询附件列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysAttachment sysAttachment) {
        startPage();
        List<SysAttachment> list = sysAttachmentService.selectSysAttachmentList(sysAttachment);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @GetMapping("/export")
    public AjaxResult export(SysAttachment sysAttachment) {
        List<SysAttachment> list = sysAttachmentService.selectSysAttachmentList(sysAttachment);
        ExcelUtil<SysAttachment> util = new ExcelUtil<SysAttachment>(SysAttachment.class);
        return util.exportExcel(list, "附件数据");
    }

    /**
     * 获取附件详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysAttachmentService.selectSysAttachmentById(id));
    }

    /**
     * 新增附件
     */
    @PostMapping
    public AjaxResult add(@RequestBody SysAttachment sysAttachment) {
        return toAjax(sysAttachmentService.insertSysAttachment(sysAttachment));
    }

    /**
     * 修改附件
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SysAttachment sysAttachment) {
        return toAjax(sysAttachmentService.updateSysAttachment(sysAttachment));
    }

    /**
     * 删除附件
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysAttachmentService.deleteSysAttachmentByIds(ids));
    }
}
